<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let loginList = [
        { userName: 'admin', password: 'admin321' },
        { userName: 'zhangsan', password: 'zs321' },
        { userName: 'lisi', password: 'ls321' },
        { userName: 'yyqx', password: 'yyqx321' },
      ]
      let userInfo = {
        token1: {
          city: '杭州',
          money: '1000w',
          sex: '女',
          userName: 'admin',
          password: 'admin321',
        },
        token2: {
          city: '北京',
          money: '1100w',
          sex: '女',
          userName: 'zhangsan',
          password: 'zs321',
        },
        token3: {
          city: '北京',
          money: '800w',
          sex: '男',
          userName: 'lisi',
          password: 'ls321',
        },
        token4: {
          city: '天津',
          money: '600w',
          sex: '男',
          userName: 'yyqx',
          password: 'yyqx321',
        },
      }
      function accountNumber(a, b) {
        //登录注册
        let registerObj = {}
        let faly = true
        let newsum = a.length + 1
        let newname = ''
        let newword = ''
        for (;;) {
          let temporaryName
          let temporaryword
          for (;;) {
            temporaryName = prompt('请输入用户名')
            temporaryword = prompt('请输入密码')
          if(!( temporaryName &&  temporaryword)){
            alert('不能为空')
          }else{
            break
          }
          }
          for (let i = 0; i < a.length; i++) {
            if (
              temporaryName === a[i].userName &&
              temporaryword === a[i].password
            ) {
              newname = a[i].userName
              newword = a[i].password
              alert('登录成功')
              break
            } else if (
              (temporaryName !== a[i].userName ||
                temporaryword !== a[i].passwordif) &&
              !faly
            ) {
              newsum--
            }
          }
          if (newsum === 0 && !faly) {
            alert('你已经没机会了')
            return
          }
          if (temporaryName === newname && temporaryword === newword) {
            break
          }

          for (let j = 0; j < a.length; j++) {
            let registerName
            let registerword
            if (temporaryName !== a[j].userName) {
              let register = +prompt(`
            账号未注册 请输入以下操作
            1.注册账号
            2.退出`)
              if (register === 1) {
                faly = false
                for (;;) {
                  registerName = prompt('请输入新用户名')
                  registerword = prompt('请输入新密码')
                  if (registerName.length < 3 && registerword.length < 3) {
                    alert('用户名和密码不能小于3')
                  } else {
                    break
                  }
                }
                registerObj.userName = registerName
                registerObj.password = registerword
                a.push(registerObj)
                alert('注册成功')
                console.log(a)
                break
              } else if (register === 2) {
                return
              } else {
                alert('请输入正确的操作')
              }
            }
          }
        }
        let sum = String(Math.floor(Math.random() * 4) + 1)
        let token = 'token' + sum
        registerObj.token = token
        for (let k in b) {
          if (token === k) {
            alert(`
            city: ${b[k].city}
            money: ${b[k].money}
            sex: ${b[k].sex}
            userName:${newname}
            `)
          }
        }
      }

      accountNumber(loginList, userInfo)
    </script>
  </body>
</html>
